<?php
namespace App\Services;
use App\Models\CourseCommentModel;
use App\Models\MemberModel;

class CourseCommentService{
	/**
	 * 插入课程评论
	 * @param array $data
	 * @return bool $res
	 */
	public function insertComment($data){
		$res = CourseCommentModel::insert($data);
		return $res;
	}

	/**
	 * 获取评论数量
	 * @param int $courseid
	 * @return int CommentNum
	 */
	public function getCommentNum($courseid){
		$commentNum = CourseCommentModel::where('isshow',1)->where('curriculum_id',$courseid)->select('id')->count();
		return $commentNum;
	}

	/**
	 * 获取评论列表
	 * @param int $courseid
	 * @return object $commentList
	 */
	public function getCommentList($courseid){
		$commentList = CourseCommentModel::where('isshow',1)->where('curriculum_id',$courseid)->select('member_id','content','add_date')->get();
		foreach($commentList as $ctm=>$cst){
			$member_info = MemberModel::where('id',$cst->member_id)->select('nick','thumb')->first();
			$commentList[$ctm]->member_thumb = $member_info->thumb;
			$commentList[$ctm]->member_nick = $member_info->nick;

			unset($member_info);
		}

		return $commentList;
	}

}